<template>
  <div id="app" :class="{'a':title}">
    <transition name="router-fade" mode="out-in">
      <router-view></router-view>
    </transition>
    <!--<router-view></router-view>-->
    <div id='rtt' class="scroll-top">
      <icon-svg iconClass="dingbu" class="scroll-top--icon"></icon-svg>
    </div>

  </div>
</template>

<script>
  require('./util/dynamicEffect/scrollTop')
  require('./../static/flexible/flexible.js')
  import {setTitle, callCode} from './util/util'
  import {callWxCode, callGetOpenId} from './api/client/login_api'
  import {params} from 'util/lib/weixin'
  import Storage from 'util/lib/storage'
  export default {
    name: 'app',
    computed: {
      title(){
        if (this.$route.query && this.$route.query.title) {
          setTitle(this.$route.query.title)
          return this.$route.query.title
        }else if (this.$route.meta.pageTitle) {
          setTitle(this.$route.meta.pageTitle)
          return this.$route.meta.pageTitle
        }
      }
    },
    methods: {
      loadScript(url, func) {
        var head = document.head || document.getElementsByTagName('head')[0];
        var meta = document.head || document.getElementsByTagName('meta')[0];
        var script = document.createElement('script');
        script.src = url;

        script.onload = script.onreadystatechange = () => {
          if(!this.readyState || this.readyState=='loaded' || this.readyState=='complete'){
            func();
            script.onload = script.onreadystatechange = null;
          }
        };

        head.insertBefore(script, meta);
      },
    },
    created() {

      // 方式二
     //  callCode()

      // window.location.href = 'http://dwz.cn/67j84S'
      // callWxCode().then(({data}) => {
      //  console.log(' callWxCode : ', callWxCode)
      // })
      // this.loadScript('https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx0ee2effdfc2706e1&redirect_uri=http%3A%2F%2Frxylwx.malrro.com%2F&response_type=code&scope=snsapi_base&state=/&#wechat_redirect',function(){
      //  console.log('loaded')}
      // );
    },
    mounted() {
      // 微信跳转
      if (params.code) {
        callGetOpenId(params.code).then(({data}) => {
           if(data.openid) {
              Storage.set("openid", data.openid)
           }
        }, ()=> {})
      }

    }
  }
</script>

<style lang="scss">
  @import "./assets/sass/main";
  #app {
    font-family: 'Avenir', Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    height: 100%;
  }
  //直达顶部
  .scroll-top{
    display: none;
    @include notStatic(fixed, auto,10px,10px,auto,5);
    width: 30px;
    height: 30px;
    line-height: 30px;
    text-align: center;
    @include borRadius(50%);
    background: #ddd;
  }
  .scroll-top--icon{
    @include fontDpr(18px);
  }
  .router-fade-enter-active, .router-fade-leave-active {
    transition: opacity 0s;
  }
  .router-fade-enter, .router-fade-leave-active {
    opacity: 0;
  }
</style>


